#include<at89c51ed2.h>
#include<stdio.h>
#include<mcs51reg.h>
#include<stdlib.h>
#include<string.h>
#include "io.h"
#include "glcd.h"





/*Code Reference : Bresenham Line Algorithm http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm*/
void drawBLine(int x1,int y1,int x2,int y2)
{

	int deltax,deltay;
	int x,y,steep;
	int error,ystep;
	
	int swapper;

	

	steep=getAbsValue(y1,y2)-getAbsValue(x1,x2);


	if(steep>0) //check this
	{
		swapper=x1;
		x1=y1;
		y1=swapper;
		
		swapper=x2;
		x2=y2;
		y2=swapper;
		
	}

	if(x1>x2)
	{
		swapper=x1;
		x1=x2;
		x2=swapper;
		
		swapper=y1;
		y1=y2;
		y2=swapper;

	}
	
	
	deltax = x2 - x1;
	
	deltay =getAbsValue(y2,y1);  
	
	error = deltax / 2;
	
	y = y1;
	
	if(y1<y2)
	{
		ystep=1;
	}
	else
	{
		ystep=-1;
	}
	

	for(x=x1;x<=x2;x++)
	{

		if(steep>0)
		{
		
			glcd_setPixel(y,x);
		}
		else
		{
			
			glcd_setPixel(x,y);
		}
	
	
   		error = error - deltay;
		if (error < 0)
		{
			y = y + ystep;
			error = error + deltax;
    	}
	}
}


	